package com.superzqb.asus.superzqbActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Handler;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextView;

import com.superzqb.asus.superzqb.R;

import static com.superzqb.asus.superzqb.R.id.textView;

public class Welcome extends Activity {
    // 声明控件对象
    private Button btn;
    private int count = 5;
    private Animation animation;
    private boolean isJump = false;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.welcome);
        btn=(Button)findViewById(R.id.jump) ;
        animation = AnimationUtils.loadAnimation(this, R.anim.animation_text);
        mHandler.sendEmptyMessageDelayed(GOTO_MAIN_ACTIVITY, 1000);
    }
    private void getCount() {
        count--;
        btn.setText(count + "秒跳过");
        animation.reset();
    }
    private static final int GOTO_MAIN_ACTIVITY = 0;
    public Handler mHandler = new Handler(){
        public void handleMessage(android.os.Message msg) {
            if (msg.what == 0) {
                getCount();
                if (count != 1) {
                    mHandler.sendEmptyMessageDelayed(0, 1000);
                } else {
                    mHandler.sendEmptyMessageDelayed(1, 1000);
                }
            } else if (msg.what == 1 && !isJump) {
                Intent intent = new Intent(Welcome.this,
                        Main.class);
                startActivity(intent);
                finish();
            }
        }
    };
    public void onJump(View view) {
        Intent intent = new Intent(Welcome.this, Main.class);
        startActivity(intent);
        isJump = true;
        finish();
    }
}
